package org.springboot.sample.config.viewresolver.view;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;


/**
 * PDF视图输出
 *
 * @author   单红宇(365384722)
 * @myblog  http://blog.csdn.net/catoop/
 * @create    2016年2月27日
 */
public class PdfView extends AbstractPdfView {

	@Override
	protected void buildPdfDocument(Map<String, Object> model, Document document, PdfWriter writer,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		  PdfPTable table = new PdfPTable(2);
		  table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
		  table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
		  table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
		  // 这里为了测试，实际应用中，我们从model中读取值
		  table.addCell("ID");
		  table.addCell("NAME");
		  table.addCell("100");
		  table.addCell("Shanhy");
		  document.add(table);
	}

}
